﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace becom.DAL
{
	/// <summary>
	/// 数据访问类:oa_family_record
	/// </summary>
	public partial class oa_family_record
	{
		public oa_family_record()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperMySQL.GetMaxID("record_id", "oa_family_record"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int record_id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from oa_family_record");
			strSql.Append(" where record_id=@record_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@record_id", MySqlDbType.Int32)
};
			parameters[0].Value = record_id;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(becom.Model.oa_family_record model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into oa_family_record(");
			strSql.Append("person_id,card_id,name,relationship,record_date)");
			strSql.Append(" values (");
			strSql.Append("@person_id,@card_id,@name,@relationship,@record_date)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@person_id", MySqlDbType.Int32,11),
					new MySqlParameter("@card_id", MySqlDbType.VarChar,32),
					new MySqlParameter("@name", MySqlDbType.VarChar,32),
					new MySqlParameter("@relationship", MySqlDbType.VarChar,32),
					new MySqlParameter("@record_date", MySqlDbType.DateTime)};
			parameters[0].Value = model.person_id;
			parameters[1].Value = model.card_id;
			parameters[2].Value = model.name;
			parameters[3].Value = model.relationship;
			parameters[4].Value = model.record_date;

			DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(becom.Model.oa_family_record model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update oa_family_record set ");
			strSql.Append("person_id=@person_id,");
			strSql.Append("card_id=@card_id,");
			strSql.Append("name=@name,");
			strSql.Append("relationship=@relationship,");
			strSql.Append("record_date=@record_date");
			strSql.Append(" where record_id=@record_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@person_id", MySqlDbType.Int32,11),
					new MySqlParameter("@card_id", MySqlDbType.VarChar,32),
					new MySqlParameter("@name", MySqlDbType.VarChar,32),
					new MySqlParameter("@relationship", MySqlDbType.VarChar,32),
					new MySqlParameter("@record_date", MySqlDbType.DateTime),
					new MySqlParameter("@record_id", MySqlDbType.Int32,11)};
			parameters[0].Value = model.person_id;
			parameters[1].Value = model.card_id;
			parameters[2].Value = model.name;
			parameters[3].Value = model.relationship;
			parameters[4].Value = model.record_date;
			parameters[5].Value = model.record_id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int record_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_family_record ");
			strSql.Append(" where record_id=@record_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@record_id", MySqlDbType.Int32)
};
			parameters[0].Value = record_id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string record_idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_family_record ");
			strSql.Append(" where record_id in ("+record_idlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public becom.Model.oa_family_record GetModel(int record_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select record_id,person_id,card_id,name,relationship,record_date from oa_family_record ");
			strSql.Append(" where record_id=@record_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@record_id", MySqlDbType.Int32)
};
			parameters[0].Value = record_id;

			becom.Model.oa_family_record model=new becom.Model.oa_family_record();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["record_id"]!=null && ds.Tables[0].Rows[0]["record_id"].ToString()!="")
				{
					model.record_id=int.Parse(ds.Tables[0].Rows[0]["record_id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["person_id"]!=null && ds.Tables[0].Rows[0]["person_id"].ToString()!="")
				{
					model.person_id=int.Parse(ds.Tables[0].Rows[0]["person_id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["card_id"]!=null && ds.Tables[0].Rows[0]["card_id"].ToString()!="")
				{
					model.card_id=ds.Tables[0].Rows[0]["card_id"].ToString();
				}
				if(ds.Tables[0].Rows[0]["name"]!=null && ds.Tables[0].Rows[0]["name"].ToString()!="")
				{
					model.name=ds.Tables[0].Rows[0]["name"].ToString();
				}
				if(ds.Tables[0].Rows[0]["relationship"]!=null && ds.Tables[0].Rows[0]["relationship"].ToString()!="")
				{
					model.relationship=ds.Tables[0].Rows[0]["relationship"].ToString();
				}
				if(ds.Tables[0].Rows[0]["record_date"]!=null && ds.Tables[0].Rows[0]["record_date"].ToString()!="")
				{
					model.record_date=DateTime.Parse(ds.Tables[0].Rows[0]["record_date"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select record_id,person_id,card_id,name,relationship,record_date ");
			strSql.Append(" FROM oa_family_record ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "oa_family_record";
			parameters[1].Value = "record_id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

